/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.bus.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.bus.entity.VaccineNotice;
import com.thinkgem.jeesite.modules.bus.service.VaccineNoticeService;

/**
 * 疫苗补助须知Controller
 * @author zxl
 * @version 2019-08-12
 */
@Controller
@RequestMapping(value = "${adminPath}/bus/vaccineNotice")
public class VaccineNoticeController extends BaseController {

	@Autowired
	private VaccineNoticeService vaccineNoticeService;
	
	@ModelAttribute
	public VaccineNotice get(@RequestParam(required=false) String id) {
		VaccineNotice entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = vaccineNoticeService.get(id);
		}
		if (entity == null){
			entity = new VaccineNotice();
		}
		return entity;
	}
	
	@RequiresPermissions("bus:vaccineNotice:view")
	@RequestMapping(value = {"list", ""})
	public String list(VaccineNotice vaccineNotice, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<VaccineNotice> page = vaccineNoticeService.findPage(new Page<VaccineNotice>(request, response), vaccineNotice); 
		model.addAttribute("page", page);
		return "modules/bus/vaccineNoticeList";
	}
	/**
	 * @author Zhang Xingliang
	 * @description 疫苗补助须知新增和修改
	 * @date 16:01 2019/8/12 0012
	 * @param vaccineNotice, model
	 * @return java.lang.String
	 **/
	@RequiresPermissions("bus:vaccineNotice:view")
	@RequestMapping(value = "form")
	public String form(VaccineNotice vaccineNotice, Model model) {

//		vaccineNotice = vaccineNoticeService.findVaccineNotice(vaccineNotice);
		model.addAttribute("vaccineNotice", vaccineNotice);
		return "modules/bus/vaccineNoticeForm";
	}

	@RequiresPermissions("bus:vaccineNotice:edit")
	@RequestMapping(value = "save")
	public String save(VaccineNotice vaccineNotice, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, vaccineNotice)){
			return form(vaccineNotice, model);
		}
		vaccineNoticeService.save(vaccineNotice);
		addMessage(redirectAttributes, "保存疫苗补助须知成功");
		return "redirect:"+Global.getAdminPath()+"/bus/vaccineNotice/?repage";
	}
	
	@RequiresPermissions("bus:vaccineNotice:edit")
	@RequestMapping(value = "delete")
	public String delete(VaccineNotice vaccineNotice, RedirectAttributes redirectAttributes) {
		vaccineNoticeService.delete(vaccineNotice);
		addMessage(redirectAttributes, "删除疫苗补助须知成功");
		return "redirect:"+Global.getAdminPath()+"/bus/vaccineNotice/?repage";
	}

}